/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmQuanLyLopHocPhan.java
 *
 * Created on Feb 26, 2013, 12:24:10 AM
 */
package design;

import Dao.DangkiHP;
import Dao.Dangnhap;
import Dao.HocPhanDao;
import Dao.Ngaysinh;
import Dao.QuanliLopHocphan;
import Entity.HocPhanEntity;
import Util.ConSQL;
import Util.Util;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Thuyngaytho
 */
public class frmQuanLyLopHocPhan extends javax.swing.JFrame {

    private String maLopHP;
    String tenLopHP;
    String maKhoa;
    String maNienkhoa;
    String maMon;
    String ngaybatdau;
    String ngayketthuc;
    int soSV;
    int SoSVDK;
    String maPB, tenPB, matkhau;
    Vector tableRecord = new Vector();
    Vector tableTitle = new Vector();
    QuanliLopHocphan qllhp = new QuanliLopHocphan();
    ConSQL conn = new ConSQL();
    DangkiHP dangkiHP = new DangkiHP();
    private DefaultTableModel tableModel, modelSearch;
    private ArrayList<HocPhanEntity> arrHocPhan;
    private HocPhanDao hpDao = new HocPhanDao();
    private HocPhanEntity hpEntity;
    private Util util = new Util();

    /**
     * Creates new form frmQuanLyLopHocPhan
     */
    public frmQuanLyLopHocPhan() throws Exception {
        initComponents();
        this.setSize(950, 750);
        //khoi tao gia tri cho cbb
        qllhp.cbbtenMon(cbbmonhoc);
        qllhp.cbbtenkhoa(cbbkhoa);
        qllhp.cbbNienkhoa(cbbnienkhoa);
        //cbb ngay bat dau
        qllhp.cbbNgay(cbbNgayBĐ);
        qllhp.cbbThang(cbbThangBĐ);
        qllhp.cbbNam(cbbNamBĐ);
//        qllhp.cbbSearch(cbbChon);
        
        //cbb ngay ket thuc
        qllhp.cbbNgay(cbbNgayKT);
        qllhp.cbbThang(cbbThangKT);
        qllhp.cbbNam(cbbNamKT);
//        qllhp.cbbGiaoVien(cbbGiaoVsien);
        //
        btnXoa.setEnabled(false);
        btnSua.setEnabled(false);
        //
        loadComboBoxSearch();
        createTitle();
        loadGiaoVien();
        LoadInformotion();
    }

    
    public frmQuanLyLopHocPhan(String maPB, String tenPB, String matkhau) throws Exception {
        initComponents();
        this.setSize(950, 750);
        //khoi tao gia tri cho cbb
        qllhp.cbbtenMon(cbbmonhoc);
        qllhp.cbbtenkhoa(cbbkhoa);
        qllhp.cbbNienkhoa(cbbnienkhoa);
        //cbb ngay bat dau
        qllhp.cbbNgay(cbbNgayBĐ);
        qllhp.cbbThang(cbbThangBĐ);
        qllhp.cbbNam(cbbNamBĐ);
        qllhp.cbbSearch(cbbChon);
        //cbb ngay ket thuc
        qllhp.cbbNgay(cbbNgayKT);
        qllhp.cbbThang(cbbThangKT);
        qllhp.cbbNam(cbbNamKT);
        //
        btnXoa.setEnabled(false);
        btnSua.setEnabled(false);
        //
        this.maPB = maPB;
        this.tenPB = tenPB;
        this.matkhau = matkhau;
        //
        lbMaPB.setText(maPB);
        lbTenPB.setText(tenPB);
        loadComboBoxSearch();
        createTitle();
        loadGiaoVien();
        LoadInformotion();
        //
        createTitle();
    }

    private void loadComboBoxSearch(){
        cbbChon.removeAllItems();
        cbbChon.addItem("Mã lớp học phần");
        cbbChon.addItem("Tên lớp học phần");
    }
    
    public void clearTF() {
        tfMaHP.setText("");
        tfSoSV.setText("");
        tfTenLopHP.setText("");
        cbbkhoa.setSelectedIndex(0);
        cbbnienkhoa.setSelectedIndex(0);
        cbbmonhoc.setSelectedIndex(0);
        cbbNgayBĐ.setSelectedIndex(0);
        cbbThangBĐ.setSelectedIndex(0);
        cbbNamBĐ.setSelectedIndex(0);
        cbbNgayKT.setSelectedIndex(0);
        cbbThangKT.setSelectedIndex(0);
        cbbNamKT.setSelectedIndex(0);
    }

    public void createTitle() {
        tableTitle.removeAllElements();
        tableTitle.addElement("Mã lớp HP");
        tableTitle.addElement("Tên lớp HP");
        tableTitle.addElement("Mã khoa");
        tableTitle.addElement("Mã niên khóa");
        tableTitle.addElement("Mã môn");
        tableTitle.addElement("Ngày bắt đầu");
        tableTitle.addElement("Ngày kết thúc");
        tableTitle.addElement("Số sinh viên");
        tableTitle.addElement("Số sinh viên ĐK");
        tableTitle.addElement("Giáo viên");
    }

    public void creatRecord(ResultSet rs) throws SQLException, Exception {
        tableRecord.removeAllElements();
        while (rs.next()) {
            Vector data = new Vector();
            data.add(rs.getString(1).toString());
            data.add(rs.getString(2).toString());
            data.add(rs.getString(3).toString());
            data.add(rs.getString(4).toString());
            data.add(rs.getString(5).toString());
            data.add(rs.getString(6).toString());
            data.add(rs.getString(7).toString());
            data.add(rs.getString(8).toString());
            data.add(rs.getString(9).toString());
            data.add(dangkiHP.layTenGiaovienDay(rs.getString(1).toString()));
            tableRecord.add(data);
        }
    }
    //

    public String layngay(JComboBox cbbNgay, JComboBox cbbThang, JComboBox cbbNam) {
        return cbbThang.getSelectedItem().toString() + "/" + cbbNgay.getSelectedItem().toString() + "/" + cbbNam.getSelectedItem().toString();
    }
    //
    private DefaultComboBoxModel comboBoxModel;

    private void loadGiaoVien() {
        comboBoxModel = new DefaultComboBoxModel();
        try {
            PreparedStatement ps = ConSQL.getCon().prepareStatement("select tenGV from giaoVien");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                comboBoxModel.addElement(rs.getString("tenGV"));
            }
            cbbGiaoVien.setModel(comboBoxModel);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

    }

    public void LoadInformotion() {
        tableModel = new DefaultTableModel();
        tableModel.setRowCount(0);

        Vector col = new Vector();
        col.addElement("Mã Lớp");
        col.addElement("Tên Lớp");
        col.addElement("Khoa");
        col.addElement("Môn học");
        col.addElement("Niên khóa");
        col.addElement("Tên giáo viên");
        col.addElement("Ngày bắt đầu");
        col.addElement("Ngày kết thúc");
        col.addElement("Số sinh viên");
        tableModel.setColumnIdentifiers(col);
        arrHocPhan = hpDao.getAll();
        for (int i = 0; i < arrHocPhan.size(); i++) {
            hpEntity = arrHocPhan.get(i);
            Vector row = new Vector();
            row.addElement(hpEntity.getMalopHP());
            row.addElement(hpEntity.getTenlopHP());
            row.addElement(hpEntity.getMakhoa());
            row.addElement(hpEntity.getMaMH());
            row.addElement(hpEntity.getMaNK());
            row.addElement(hpEntity.getMaGV());
            row.addElement(hpEntity.getNgayBD());
            row.addElement(hpEntity.getNgayKT());
            row.addElement(hpEntity.getSoSV());

            tableModel.addRow(row);
        }
        tbContent.setModel(tableModel);
    }
    public void LoadInSearch(String str, int id) {
        tableModel = new DefaultTableModel();
        tableModel.setRowCount(0);

        Vector col = new Vector();
        col.addElement("Mã Lớp");
        col.addElement("Tên Lớp");
        col.addElement("Khoa");
        col.addElement("Môn học");
        col.addElement("Niên khóa");
        col.addElement("Tên giáo viên");
        col.addElement("Ngày bắt đầu");
        col.addElement("Ngày kết thúc");
        col.addElement("Số sinh viên");
        tableModel.setColumnIdentifiers(col);
        if(id == 0){
            arrHocPhan = hpDao.timKiem(str, 0);
        }else{
            arrHocPhan = hpDao.timKiem(str, 1);
        }
        
        for (int i = 0; i < arrHocPhan.size(); i++) {
            hpEntity = arrHocPhan.get(i);
            Vector row = new Vector();
            row.addElement(hpEntity.getMalopHP());
            row.addElement(hpEntity.getTenlopHP());
            row.addElement(hpEntity.getMakhoa());
            row.addElement(hpEntity.getMaMH());
            row.addElement(hpEntity.getMaNK());
            row.addElement(hpEntity.getMaGV());
            row.addElement(hpEntity.getNgayBD());
            row.addElement(hpEntity.getNgayKT());
            row.addElement(hpEntity.getSoSV());

            tableModel.addRow(row);
        }
        tbContent.setModel(tableModel);
    }
    //cac phuong thuc kiem tra input
    Ngaysinh ns = new Ngaysinh();

    public String CheckDate() {
        String cBD = "";
        String cKT = "";
        int c = 0;
        int ngayBD = Integer.parseInt(cbbNgayBĐ.getSelectedItem().toString());
        int thangBD = Integer.parseInt(cbbThangBĐ.getSelectedItem().toString());
        int namBD = Integer.parseInt(cbbNamBĐ.getSelectedItem().toString());
        if (ns.validDate(ngayBD, thangBD, namBD) == false) {
            cBD = "Định dạng ngày bắt đầu không tồn tại!\n";
            c = 1;
        }
        int ngayKT = Integer.parseInt(cbbNgayKT.getSelectedItem().toString());
        int thangKT = Integer.parseInt(cbbThangKT.getSelectedItem().toString());
        int namKT = Integer.parseInt(cbbNamKT.getSelectedItem().toString());
        if (ns.validDate(ngayKT, thangKT, namKT) == false) {
            cBD = "Định dạng ngày bắt đầu không tồn tại!";
            c = 1;
        }
        if (c == 0) {
            Date bd = new Date();
            Date kt = new Date();
            if (layngay(cbbNgayBĐ, cbbThangBĐ, cbbNamBĐ).equalsIgnoreCase(layngay(cbbNgayKT, cbbThangKT, cbbNamKT))) {
                return "Ngày bắt đầu và kết thúc trùng nhau!";
            } else {
                bd.setDate(ngayBD);
                kt.setDate(ngayKT);
                bd.setMonth(thangBD);
                kt.setMonth(thangKT);
                bd.setYear(namBD);
                kt.setYear(namKT);
                if (bd.compareTo(kt) == 1) {
                    return "Ngày kết thúc phải sau ngày bắt đầu!";
                }
            }
        }
        return cBD + cKT;
    }

    public String CheckInput() throws Exception {
        String cMalop = "", cTenlop = "", cSoSV = "";
        int nSoSV;
        //kiem tra ma lop
        if (tfMaHP.getText().trim().equals("")) {
            cMalop = "Mã lớp không được để trống!\n";
        } else {
            Statement st = conn.getCon().createStatement();
            ResultSet rs = st.executeQuery("select * from lopHP where maLopHP='" + tfMaHP.getText().trim() + "';");
            if (rs.next()) {
                cMalop = "Trùng mã lớp!\n";
            }
        }
        //kiem tra ten lop
        if (tfTenLopHP.getText().trim().equals("")) {
            cTenlop = "Tên lớp không được để trống!\n";
        }
        //kiem tra so sinh vien nhap
        try {
            nSoSV = Integer.parseInt(tfSoSV.getText().trim());
            if (nSoSV <= 0) {
                cSoSV = "Số sinh viên phải lớn hơn 0!\n";
            }
        } catch (Exception e) {
            e.printStackTrace();
            cSoSV = "Số sinh viên phải là số!\n";
        }
        return cMalop + cTenlop + cSoSV + CheckDate();
    }
    //

    public String layMaGiaovien(String tenGV) throws Exception {
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select maGV from giaoVien where tenGV=N'" + tenGV + "'");
        if (rs.next()) {
            return rs.getString(1);
        }
        return rs.getString(1);
    }
    //   
    //cac phuong thuc them sua xoa

    public void Them() throws Exception {
//        LoadInput();
        if (CheckInput().equals("")) {
            maLopHP = tfMaHP.getText();
            tenLopHP = tfTenLopHP.getText();
            maKhoa = util.getMa(cbbkhoa.getSelectedItem().toString(), "makhoa", "tenkhoa", "khoa");
            maMon = util.getMa(cbbmonhoc.getSelectedItem().toString(), "maMH", "tenMH", "monHoc");
            maNienkhoa = util.getMa(cbbnienkhoa.getSelectedItem().toString(), "maNK", "tenNK", "nienKhoa");
            ngaybatdau = cbbNgayBĐ.getSelectedItem().toString() + "/" + cbbThangBĐ.getSelectedItem().toString() + "/"
                    + cbbNamBĐ.getSelectedItem().toString();
            ngayketthuc = cbbNgayKT.getSelectedItem().toString() + "/" + cbbThangKT.getSelectedItem().toString() + "/"
                    + cbbNamKT.getSelectedItem().toString();
            String tenGV = cbbGiaoVien.getSelectedItem().toString();
            String maGV = layMaGiaovien(tenGV);
           soSV = Integer.parseInt(tfSoSV.getText());
            SoSVDK = Integer.parseInt(tfSoSV.getText());
            
            String sql = "insert into lopHP values(N'" + maLopHP + "',N'" + tenLopHP + "','" + maKhoa + "','"
                    + "" + maNienkhoa + "','" + maMon + "','" + maGV + "','" + ngaybatdau + "','" + ngayketthuc + "','"+ soSV +"','" + SoSVDK + "')";
            
            PreparedStatement ps = ConSQL.getCon().prepareStatement(sql);
            int rs = ps.executeUpdate();
            if(rs>0){
                ps = ConSQL.getCon().prepareStatement("insert into giaoVien_lopHP values('" + maGV + "','" + maLopHP + "');");
                JOptionPane.showMessageDialog(rootPane, "Thêm thành công!");
            LoadInformotion();
            loadGiaoVien();
            clearTF();
            }else{
                JOptionPane.showMessageDialog(rootPane, "Thêm thất bại!");
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, CheckInput());
        }

    }
    //

    private boolean checkTextField(JTextField jtf, String strName) {
        if (jtf.getText().trim().equals("")) {
            JOptionPane.showMessageDialog(null, strName + " không được để trống");
            jtf.requestFocus();
            return false;
        }
        return true;
    }

    public void Sua() throws Exception {
        if (checkTextField(tfMaHP, "Mã học phần")) {
            if (checkTextField(tfTenLopHP, "Tên lớp học phần")) {
                if (checkTextField(tfSoSV, "Số sinh viên")) {
                    maLopHP = tfMaHP.getText();
                    tenLopHP = tfTenLopHP.getText();
                    maKhoa = util.getMa(cbbkhoa.getSelectedItem().toString(), "makhoa", "tenkhoa", "khoa");
                    maMon = util.getMa(cbbmonhoc.getSelectedItem().toString(), "maMH", "tenMH", "monHoc");
                    maNienkhoa = util.getMa(cbbnienkhoa.getSelectedItem().toString(), "maNK", "tenNK", "nienKhoa");
                    ngaybatdau = cbbNgayBĐ.getSelectedItem().toString() + "/" + cbbThangBĐ.getSelectedItem().toString() + "/"
                            + cbbNamBĐ.getSelectedItem().toString();
                    ngayketthuc = cbbNgayKT.getSelectedItem().toString() + "/" + cbbThangKT.getSelectedItem().toString() + "/"
                            + cbbNamKT.getSelectedItem().toString();
                    String tenGV = cbbGiaoVien.getSelectedItem().toString();
                    String maGV = layMaGiaovien(tenGV);
                    SoSVDK = Integer.parseInt(tfSoSV.getText());

                    String sql = "update lopHP set tenLopHP=N'" + tenLopHP + "',makhoa='" + maKhoa + "',maNK='" + maNienkhoa + "',maMH='" + maMon + "'"
                            + ",maGV='" + maGV + "',ngayBatdau='" + ngaybatdau + "',ngayKetthuc='" + ngayketthuc + "',siSo=" + SoSVDK + ",soHSDK="+SoSVDK
                            + "where maLopHP='" + maLopHP + "'";
                    PreparedStatement ps = ConSQL.getCon().prepareStatement(sql);
                    int kq = ps.executeUpdate();
                    if (kq > 0) {
                        JOptionPane.showMessageDialog(null, "Cập nhật thành công");
                        LoadInformotion();
                        clearTF();
                    } else {
                        JOptionPane.showMessageDialog(null, "Cập nhật thất bại");
                    }
                }
            }
        }
    }

    public void Xoa() throws Exception {
        if (checkTextField(tfMaHP, "Mã học phần")) {
            maLopHP = tfMaHP.getText();
            PreparedStatement ps1 = ConSQL.getCon().prepareStatement("delete from giaoVien_lopHP where maLopHP=N'" + maLopHP + "'");
            ps1.executeUpdate();
            PreparedStatement ps = ConSQL.getCon().prepareStatement("delete from lopHP where maLopHP =N'" + maLopHP + "'");
            int kq = ps.executeUpdate();
            if (kq > 0) {
                JOptionPane.showMessageDialog(null, "Xóa thành công");
                LoadInformotion();
                clearTF();
            } else {
                JOptionPane.showMessageDialog(null, "Xóa thất bại");
            }
        }
    }
    //

    public void Tim() throws Exception {
  
        int iChon = cbbChon.getSelectedIndex();
        String str = tfSearch.getText();
        if(iChon == 0){
            LoadInSearch(str, 0);
        }else{
            LoadInSearch(str, 1);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lbMaPB = new javax.swing.JLabel();
        lbTenPB = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        tfMaHP = new javax.swing.JTextField();
        tfTenLopHP = new javax.swing.JTextField();
        cbbkhoa = new javax.swing.JComboBox();
        cbbmonhoc = new javax.swing.JComboBox();
        cbbnienkhoa = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        cbbGiaoVien = new javax.swing.JComboBox();
        cbbNgayBĐ = new javax.swing.JComboBox();
        cbbThangBĐ = new javax.swing.JComboBox();
        cbbNamBĐ = new javax.swing.JComboBox();
        cbbNgayKT = new javax.swing.JComboBox();
        cbbThangKT = new javax.swing.JComboBox();
        cbbNamKT = new javax.swing.JComboBox();
        tfSoSV = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        btnThem = new javax.swing.JButton();
        btnSua = new javax.swing.JButton();
        btnXoa = new javax.swing.JButton();
        btnNhapLai = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbContent = new javax.swing.JTable();
        tfSearch = new javax.swing.JTextField();
        cbbChon = new javax.swing.JComboBox();
        btnSearch = new javax.swing.JButton();
        btnThoat = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin phòng ban", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 0, 18))); // NOI18N

        jLabel1.setText("Mã phòng ban :");

        jLabel2.setText("Tên phòng ban :");

        lbMaPB.setText("Mã");

        lbTenPB.setText("Tên");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbTenPB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbMaPB, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))
                .addContainerGap(64, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lbMaPB))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lbTenPB))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 0, 18))); // NOI18N

        jLabel5.setText("Mã lớp học phần :");

        jLabel6.setText("Tên lớp học phần :");

        jLabel7.setText(" Khoa :");

        jLabel8.setText(" Môn  học:");

        jLabel9.setText("Niên khóa :");

        cbbkhoa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbbmonhoc.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbbmonhoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbbmonhocActionPerformed(evt);
            }
        });

        cbbnienkhoa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel10.setText("Giáo viên:");

        jLabel11.setText("Ngày bắt đầu ");

        jLabel12.setText("Ngày kết thúc");

        jLabel13.setText("Số sinh viên");

        cbbGiaoVien.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbbNgayBĐ.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbbThangBĐ.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbbNamBĐ.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbbNgayKT.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbbThangKT.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbbNamKT.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        tfSoSV.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tfSoSVKeyTyped(evt);
            }
        });

        jLabel14.setText("d/m/yyyy");

        jLabel15.setText("d/m/yyyy");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbbnienkhoa, 0, 156, Short.MAX_VALUE)
                    .addComponent(cbbmonhoc, 0, 156, Short.MAX_VALUE)
                    .addComponent(cbbkhoa, 0, 156, Short.MAX_VALUE)
                    .addComponent(tfTenLopHP, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
                    .addComponent(tfMaHP, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                .addGap(80, 80, 80)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(26, 26, 26)
                        .addComponent(cbbGiaoVien, 0, 202, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbbNgayBĐ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cbbThangBĐ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cbbNamBĐ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfSoSV, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbbNgayKT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cbbThangKT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cbbNamKT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(29, 29, 29)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15))
                .addGap(78, 78, 78))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tfMaHP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(cbbGiaoVien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(tfTenLopHP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(cbbNgayBĐ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbThangBĐ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbNamBĐ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel8))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbkhoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)
                            .addComponent(cbbNgayKT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbbThangKT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbbNamKT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbmonhoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13)
                            .addComponent(tfSoSV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(cbbnienkhoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setForeground(new java.awt.Color(255, 255, 255));

        btnThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Button-Add-icon (1).png"))); // NOI18N
        btnThem.setText("Thêm mới");
        btnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemActionPerformed(evt);
            }
        });

        btnSua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Edit-Document-icon.png"))); // NOI18N
        btnSua.setText("Sửa");
        btnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaActionPerformed(evt);
            }
        });

        btnXoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Button-Delete-icon (1).png"))); // NOI18N
        btnXoa.setText("Xóa");
        btnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaActionPerformed(evt);
            }
        });

        btnNhapLai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Refresh.png"))); // NOI18N
        btnNhapLai.setText("Nhập lại");
        btnNhapLai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNhapLaiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnThem)
                .addGap(38, 38, 38)
                .addComponent(btnSua, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addComponent(btnXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(btnNhapLai)
                .addContainerGap(278, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnThem)
                    .addComponent(btnNhapLai)
                    .addComponent(btnXoa)
                    .addComponent(btnSua))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh sách lớp học phần", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 0, 18))); // NOI18N

        tbContent.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Mã lớp HP", "Tên lớp HP", "Mã khoa", "Mã niên khóa", "Mã môn", "Ngày bắt đầu", "Ngày kết thúc", "Số sinh viên", "Số sinh viên ĐK", "Giáo viên"
            }
        ));
        tbContent.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbContentMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbContent);

        tfSearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfSearchKeyPressed(evt);
            }
        });

        cbbChon.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btnSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Search-icon.png"))); // NOI18N
        btnSearch.setText("Tìm kiếm");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        btnThoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Turn off.png"))); // NOI18N
        btnThoat.setText("Thoát");
        btnThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(tfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(cbbChon, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64)
                .addComponent(btnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 141, Short.MAX_VALUE)
                .addComponent(btnThoat)
                .addGap(44, 44, 44))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbChon, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnThoat)
                    .addComponent(btnSearch))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemActionPerformed
// TODO add your handling code here:
    try {
        Them();
    } catch (Exception ex) {
        Logger.getLogger(frmQuanLyLopHocPhan.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_btnThemActionPerformed

private void btnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaActionPerformed
// TODO add your handling code here:
    try {
        Sua();
        btnXoa.setEnabled(false);
        btnSua.setEnabled(false);
    } catch (Exception ex) {
        Logger.getLogger(frmQuanLyLopHocPhan.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_btnSuaActionPerformed

private void btnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaActionPerformed
// TODO add your handling code here:
    int res = JOptionPane.showConfirmDialog(null, "Bạn có chắc muốn xóa không?", "Confirm", JOptionPane.YES_NO_OPTION);
    if (res == 0) {
        try {
            Xoa();
        } catch (Exception ex) {
            Logger.getLogger(frmQuanLyLopHocPhan.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}//GEN-LAST:event_btnXoaActionPerformed

private void btnNhapLaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNhapLaiActionPerformed
// TODO add your handling code here:
    clearTF();
    loadGiaoVien();
}//GEN-LAST:event_btnNhapLaiActionPerformed

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
// TODO add your handling code here:
    try {
        // TODO add your handling code here:
        Tim();
    } catch (Exception ex) {
        Logger.getLogger(frmQuanLyLopHocPhan.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_btnSearchActionPerformed

private void btnThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThoatActionPerformed
// TODO add your handling code here:
    new frmPhongBan(maPB, tenPB, matkhau).setVisible(true);
    this.setVisible(false);
}//GEN-LAST:event_btnThoatActionPerformed

private void tbContentMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbContentMouseClicked
// TODO add your handling code here:
//    LoadInformotion();
    int iDongChon = tbContent.getSelectedRow();

    tfMaHP.setText((String) tbContent.getModel().getValueAt(iDongChon, 0));
    tfTenLopHP.setText((String) tbContent.getModel().getValueAt(iDongChon, 1));
    cbbkhoa.setSelectedItem((String) tbContent.getModel().getValueAt(iDongChon, 2));
    cbbmonhoc.setSelectedItem((String) tbContent.getModel().getValueAt(iDongChon, 3));
    cbbnienkhoa.setSelectedItem((String) tbContent.getModel().getValueAt(iDongChon, 4));
    cbbGiaoVien.setSelectedItem((String) tbContent.getModel().getValueAt(iDongChon, 5));


    Date strStart, strStop;
    strStart = (Date) tbContent.getModel().getValueAt(iDongChon, 6);
    strStop = (Date) tbContent.getModel().getValueAt(iDongChon, 7);
    String[] strBD = strStart.toString().split("-");
    cbbNgayBĐ.setSelectedItem(Integer.parseInt(strBD[1]));
    cbbThangBĐ.setSelectedItem(Integer.parseInt(strBD[2]));
    cbbNamBĐ.setSelectedItem(Integer.parseInt(strBD[0]));

    String[] strKT = strStop.toString().split("-");
    cbbNgayKT.setSelectedItem(Integer.parseInt(strKT[1]));
    cbbThangKT.setSelectedItem(Integer.parseInt(strKT[2]));
    cbbNamKT.setSelectedItem(Integer.parseInt(strKT[0]));

    tfSoSV.setText("" + (int) tbContent.getModel().getValueAt(iDongChon, 8));
    btnXoa.setEnabled(true);
    btnSua.setEnabled(true);
}//GEN-LAST:event_tbContentMouseClicked

private void tfSearchKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfSearchKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == 10) {
        btnSearch.doClick();
    }
}//GEN-LAST:event_tfSearchKeyPressed

private void cbbmonhocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbbmonhocActionPerformed

}//GEN-LAST:event_cbbmonhocActionPerformed

private void tfSoSVKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfSoSVKeyTyped
// TODO add your handling code here:
    if (!Character.isDigit(evt.getKeyChar())){
        evt.consume();
    }
}//GEN-LAST:event_tfSoSVKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyLopHocPhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyLopHocPhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyLopHocPhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyLopHocPhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new frmQuanLyLopHocPhan().setVisible(true);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnNhapLai;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnSua;
    private javax.swing.JButton btnThem;
    private javax.swing.JButton btnThoat;
    private javax.swing.JButton btnXoa;
    private javax.swing.JComboBox cbbChon;
    private javax.swing.JComboBox cbbGiaoVien;
    private javax.swing.JComboBox cbbNamBĐ;
    private javax.swing.JComboBox cbbNamKT;
    private javax.swing.JComboBox cbbNgayBĐ;
    private javax.swing.JComboBox cbbNgayKT;
    private javax.swing.JComboBox cbbThangBĐ;
    private javax.swing.JComboBox cbbThangKT;
    private javax.swing.JComboBox cbbkhoa;
    private javax.swing.JComboBox cbbmonhoc;
    private javax.swing.JComboBox cbbnienkhoa;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbMaPB;
    private javax.swing.JLabel lbTenPB;
    private javax.swing.JTable tbContent;
    private javax.swing.JTextField tfMaHP;
    private javax.swing.JTextField tfSearch;
    private javax.swing.JTextField tfSoSV;
    private javax.swing.JTextField tfTenLopHP;
    // End of variables declaration//GEN-END:variables
}
